package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.CollectService;
import com.cskaoyan.service.CollectServiceImpl;
import com.cskaoyan.util.ResponseUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/collect/*")
public class AdminCollectServlet extends WdBaseServlet {

    CollectService collectService = new CollectServiceImpl();

    public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Integer page = Integer.parseInt(request.getParameter("page"));
        Integer limit = Integer.parseInt(request.getParameter("limit"));
        String order = request.getParameter("order");
        String sort = request.getParameter("sort");

        Integer valueId=null;
        if (request.getParameter("valueId")==null||request.getParameter("valueId").equals("")){
            valueId=null;
        }else {
            valueId=Integer.parseInt(request.getParameter("valueId"));
        }

        Integer userId=null;
        if (request.getParameter("userId")==null||request.getParameter("userId").equals("")){
            userId=null;
        }else {
            userId=Integer.parseInt(request.getParameter("userId"));
        }


        CommonData<MarketCollect> data = collectService.query(page,limit,sort,order,valueId,userId);
        ResponseUtil.responseJson(response, BaseRespVo.ok(data));
    }

}
